using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VAKSTRU
    {
        public DataRow Convert2AKSTRU(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryAKSTRU(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["AKUMANDANT"] = " ".PadRight(2 ); 
         dwReturn["AKUWERK"] = " ".PadRight(3 ); 
         dwReturn["AKULINIE"] = " ".PadRight(3 ); 
         dwReturn["AKUABT"] = " ".PadRight(3 ); 
         dwReturn["AKUKST"] = " ".PadRight(3 ); 
         dwReturn["AKUPOS"] = " ".PadRight(4 ); 
         dwReturn["AKUAENZL"] = " ".PadRight(0 ); 
         dwReturn["AKUAENB"] = " ".PadRight(8 ); 
         dwReturn["AKUAEND"] = " ".PadRight(0 ); 
         dwReturn["AKUNEUB"] = " ".PadRight(8 ); 
         dwReturn["AKUNEUD"] = " ".PadRight(0 ); 
         dwReturn["AKUBEZ"] = " ".PadRight(50 ); 
         dwReturn["AKUKBEZ"] = " ".PadRight(10 ); 
         dwReturn["AKUSTAKZ"] = " ".PadRight(1 ); 
         dwReturn["AKUTYP"] = " ".PadRight(8 ); 
         dwReturn["AKUPKSTKRS"] = " ".PadRight(2 ); 
         dwReturn["AKUPKST"] = " ".PadRight(4 ); 
         dwReturn["AKUWRKANT"] = " ".PadRight(0 ); 
         dwReturn["AKUWRKENGP"] = " ".PadRight(1 ); 
         dwReturn["AKULINANT"] = " ".PadRight(0 ); 
         dwReturn["AKULINENGP"] = " ".PadRight(1 ); 
         dwReturn["AKUABTANT"] = " ".PadRight(0 ); 
         dwReturn["AKUABTENGP"] = " ".PadRight(1 ); 
         dwReturn["AKUKSTANT"] = " ".PadRight(0 ); 
         dwReturn["AKUKSTENGP"] = " ".PadRight(1 ); 
         dwReturn["AKUNOZAEHL"] = " ".PadRight(1 ); 
         dwReturn["AKUGELBVON"] = " ".PadRight(0 ); 
         dwReturn["AKUGELBBIS"] = " ".PadRight(0 ); 
         dwReturn["AKUFILLER"] = " ".PadRight(64 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapAKSTRU(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveAKSTRU(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryAKSTRU(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapAKSTRU(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertAKSTRU(dwLocal, ITXDBVERSION);
            }
            UpdateAKSTRU(dwLocal);
        }
        public void InsertAKSTRU(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO AKSTRU(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryAKSTRU(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM AKSTRU WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM AKSTRU  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "AKSTRU";
            Return = Result;
            return Return;
        }
        public void DeleteAKSTRU(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM AKSTRU   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateAKSTRU(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE AKSTRU SET "
                    +"AKUMANDANT= :AKUMANDANT,"
                    +"AKUWERK= :AKUWERK,"
                    +"AKULINIE= :AKULINIE,"
                    +"AKUABT= :AKUABT,"
                    +"AKUKST= :AKUKST,"
                    +"AKUPOS= :AKUPOS,"
                    +"AKUAENZL= :AKUAENZL,"
                    +"AKUAENB= :AKUAENB,"
                    +"AKUAEND= :AKUAEND,"
                    +"AKUNEUB= :AKUNEUB,"
                    +"AKUNEUD= :AKUNEUD,"
                    +"AKUBEZ= :AKUBEZ,"
                    +"AKUKBEZ= :AKUKBEZ,"
                    +"AKUSTAKZ= :AKUSTAKZ,"
                    +"AKUTYP= :AKUTYP,"
                    +"AKUPKSTKRS= :AKUPKSTKRS,"
                    +"AKUPKST= :AKUPKST,"
                    +"AKUWRKANT= :AKUWRKANT,"
                    +"AKUWRKENGP= :AKUWRKENGP,"
                    +"AKULINANT= :AKULINANT,"
                    +"AKULINENGP= :AKULINENGP,"
                    +"AKUABTANT= :AKUABTANT,"
                    +"AKUABTENGP= :AKUABTENGP,"
                    +"AKUKSTANT= :AKUKSTANT,"
                    +"AKUKSTENGP= :AKUKSTENGP,"
                    +"AKUNOZAEHL= :AKUNOZAEHL,"
                    +"AKUGELBVON= :AKUGELBVON,"
                    +"AKUGELBBIS= :AKUGELBBIS,"
                    +"AKUFILLER= :AKUFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("AKUMANDANT", OracleType.NVarChar).Value = dwData["AKUMANDANT"].ToString(); 
          or1.Parameters.Add("AKUWERK", OracleType.NVarChar).Value = dwData["AKUWERK"].ToString(); 
          or1.Parameters.Add("AKULINIE", OracleType.NVarChar).Value = dwData["AKULINIE"].ToString(); 
          or1.Parameters.Add("AKUABT", OracleType.NVarChar).Value = dwData["AKUABT"].ToString(); 
          or1.Parameters.Add("AKUKST", OracleType.NVarChar).Value = dwData["AKUKST"].ToString(); 
          or1.Parameters.Add("AKUPOS", OracleType.NVarChar).Value = dwData["AKUPOS"].ToString(); 
          or1.Parameters.Add("AKUAENZL", OracleType.NVarChar).Value = dwData["AKUAENZL"].ToString(); 
          or1.Parameters.Add("AKUAENB", OracleType.NVarChar).Value = dwData["AKUAENB"].ToString(); 
          or1.Parameters.Add("AKUAEND", OracleType.NVarChar).Value = dwData["AKUAEND"].ToString(); 
          or1.Parameters.Add("AKUNEUB", OracleType.NVarChar).Value = dwData["AKUNEUB"].ToString(); 
          or1.Parameters.Add("AKUNEUD", OracleType.NVarChar).Value = dwData["AKUNEUD"].ToString(); 
          or1.Parameters.Add("AKUBEZ", OracleType.NVarChar).Value = dwData["AKUBEZ"].ToString(); 
          or1.Parameters.Add("AKUKBEZ", OracleType.NVarChar).Value = dwData["AKUKBEZ"].ToString(); 
          or1.Parameters.Add("AKUSTAKZ", OracleType.NVarChar).Value = dwData["AKUSTAKZ"].ToString(); 
          or1.Parameters.Add("AKUTYP", OracleType.NVarChar).Value = dwData["AKUTYP"].ToString(); 
          or1.Parameters.Add("AKUPKSTKRS", OracleType.NVarChar).Value = dwData["AKUPKSTKRS"].ToString(); 
          or1.Parameters.Add("AKUPKST", OracleType.NVarChar).Value = dwData["AKUPKST"].ToString(); 
          or1.Parameters.Add("AKUWRKANT", OracleType.NVarChar).Value = dwData["AKUWRKANT"].ToString(); 
          or1.Parameters.Add("AKUWRKENGP", OracleType.NVarChar).Value = dwData["AKUWRKENGP"].ToString(); 
          or1.Parameters.Add("AKULINANT", OracleType.NVarChar).Value = dwData["AKULINANT"].ToString(); 
          or1.Parameters.Add("AKULINENGP", OracleType.NVarChar).Value = dwData["AKULINENGP"].ToString(); 
          or1.Parameters.Add("AKUABTANT", OracleType.NVarChar).Value = dwData["AKUABTANT"].ToString(); 
          or1.Parameters.Add("AKUABTENGP", OracleType.NVarChar).Value = dwData["AKUABTENGP"].ToString(); 
          or1.Parameters.Add("AKUKSTANT", OracleType.NVarChar).Value = dwData["AKUKSTANT"].ToString(); 
          or1.Parameters.Add("AKUKSTENGP", OracleType.NVarChar).Value = dwData["AKUKSTENGP"].ToString(); 
          or1.Parameters.Add("AKUNOZAEHL", OracleType.NVarChar).Value = dwData["AKUNOZAEHL"].ToString(); 
          or1.Parameters.Add("AKUGELBVON", OracleType.NVarChar).Value = dwData["AKUGELBVON"].ToString(); 
          or1.Parameters.Add("AKUGELBBIS", OracleType.NVarChar).Value = dwData["AKUGELBBIS"].ToString(); 
          or1.Parameters.Add("AKUFILLER", OracleType.NVarChar).Value = dwData["AKUFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
